package org.boot.thread.atomic;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Arrays;

/**
 * 枚举类测试实例
 *
 * @author 李坤
 * @date 2022/8/26 16:26
 */
public enum EnumInstance {
    ACCOUNT_ONE("1", BigDecimal.ONE), ACCOUNT_TWO("2", BigDecimal.valueOf(2));

    public final String id;

    public final BigDecimal balance;

    EnumInstance(String id, BigDecimal balance) {
        this.id = id;
        this.balance = balance;
    }

    public static void main(String[] args) {
        for (Field field : EnumInstance.class.getDeclaredFields()) {
            System.out.println(field);
            try {
                field.setAccessible(true);
                System.out.println(field.getType());
                System.out.println(field.get(EnumInstance.ACCOUNT_ONE));
            } catch (IllegalAccessException exception) {
                exception.printStackTrace();
            }
        }

        System.out.println(Arrays.toString(values()));
        System.out.println(EnumInstance.valueOf("ACCOUNT_ONE"));
    }

    @Override
    public String toString() {
        return "{" + this.name() + ": id = " + id + ", balance = " + balance + "}";
    }

}
